import cancelMenuBtn from './cancelBtn'
import saveMenuBtn from './saveMenuBtn'


import { Boot } from "@wangeditor/editor";

const MenusList = [
  {
      key: 'cancelMenuBtn',
      class: cancelMenuBtn,
      index: 0 // 菜单要在工具栏显示的位置
  },
  {
    key: 'saveMenuBtn',
    class: saveMenuBtn,
    index: 1 // 菜单要在工具栏显示的位置
  }
]


const registerMenu = function (editor, toolbarConfig){
  const allRegisterMenu = editor.getAllMenuKeys(); // 获取所有已注册的菜单
  let keys = [];
  for(let item of MenusList){
      if(allRegisterMenu.indexOf(item.key) < 0){ // 如果未注册，则注册
          const menuObj = {
              key: item.key,
              factory() {
                  return new item.class()
              }
          }
          Boot.registerMenu(menuObj);
      }
      keys.push(item.key)
  }
  toolbarConfig.insertKeys = {
      index: MenusList[0].index,
      keys: keys
  }
}

export default registerMenu
